<?php
Class Manager_Model_comments extends Zend_Db_Table
{	
	protected $_name ="comments";
	protected $_primary ="id";
	
	public function list_category()
	{
		$db = Zend_Registry::get('connectDb');
        $select = $db->select()
		          ->from(array('ue' => 'category'));		          
        $results = $db->fetchAll($select);
        return $results;
	}
	public function sec_id()
	{
		$db = Zend_Registry::get('connectDb');
        $select = $db->select()
		          ->from(array('ue' => 'sections'),array('title','id'));		          
        $results = $db->fetchPairs($select);
        return $results;
	}
	
	public function listsec()
	{
		$db = Zend_Registry::get('connectDb');
        $select = $db->select()
		          ->from(array('ue' => 'sections'),array('id','title'));		          
        $results = $db->fetchPairs($select);
        return $results;
	}
	
	public function searchkq($keyword,$status,$id,$product)
	{
		$db = Zend_Registry::get('connectDb');
			   $select = $db->select()
				             ->from(array('cs' => 'comments'))
				             ->join(array('dt'=>'details_product'),'cs.product_id=dt.id',array('dt.title as tensanpham'))
		                     ->where ("cs.published=$status or $status=-1")
		                     ->where ("cs.id=$id or $id=-1")
				             ->where("cs.title like '%$keyword%'")
				             ->where ("cs.product_id=$product or $product=-1")
				             ->order('cs.id DESC');
	    $result = $db->fetchAll($select)	;
		return $result;	
	}
	
   public function delete_muti($arrParam = null)
	{
    $db = Zend_Registry::get('connectDb');
	$tblGroup = new Manager_Model_category();
		if(count($arrParam['cid'])>0)
	 	{
			$ids = implode(',', $arrParam['cid']);
			$where = 'id IN (' . $ids . ')'; 
			$tblGroup->delete($where); 
		    
		    $where = "cat_id in($ids)";
		    $db->delete('article',$where);
	 	}
	 	
	 	
	}
	
	public function delete_data($id)
	{
		  	$tblGroup = new Manager_Model_category();
			$where = "id =$id";
		    $tblGroup->delete($where);  	
	}
	
	public function getrow($id)
	{
				$db = Zend_Registry::get('connectDb');
				$query="Select * from comments  where id=$id";
				$result = $db->fetchAll($query);
				return $result;
	}
	public function edit($data)
	{
		$tblGroup = new Manager_Model_category();
		$where ='id ='.$data['id'];
    	$data1  = array('title'=>$data['title'],'published'=>$data['published'],
    	               'order'=>$data['order'],'sec_id'=>$data['sec_id']);
    	$tblGroup->update($data1,$where);
	}
	
   public  function listItemabout($status,$id,$product)
	{
		 $db     = Zend_Registry::get('connectDb');
         $select = $db->select()
		             ->from(array('cs' => 'comments'))
		             ->join(array('dt'=>'details_product'),'cs.product_id=dt.id',array('dt.title as tensanpham'))
		             ->where ("cs.published=$status or $status=-1")
		             ->where ("cs.id=$id or $id=-1")
		             ->where ("cs.product_id=$product or $product=-1")
		             ->order('cs.id DESC');		          
         $results = $db->fetchAll($select);
         return $results;
	}
	
   public function save($data)
	{	
      $introtext = stripslashes($data['introtext']);
	  
	  if ($data['key']=='add')
		  {	
			$db = Zend_Registry::get('connectDb');
		  	$data1 = array(
			              	'title'         	=> $data['title'],
		  	                'name'         	=> $data['images'],
		  	                'email'	        => $introtext,
		                	'address'	    => $data['section_id'],
		  	                'fulltext'			=> $data['published'],
		  	                'published'			=> $data['featured'],
							'product_id'	            => $data['order'],
	                        'order'	    => $data['language_id'],
		  			 );
	        $db->insert('category', $data1);
		  }
	else 
		  {

		  $tblGroup = new Manager_Model_comments();
		  $where ='id ='.$data['id'];
    	  $data1 = array(
			              	'fulltext'         	=> $introtext,
		  	             );
		  
    	  $tblGroup->update($data1,$where);
		  
		  }  
     }
     
	 public function delete_data_group($id)
	{
		  	$db = Zend_Registry::get('connectDb');
			$where = "categorys_id =$id";
		    $db->delete('user_privileges',$where);  	
	}
	
  public function delete_data_content($id)
	{
		  	$db = Zend_Registry::get('connectDb');
			$where = "cat_id =$id";
		    $db->delete('article',$where);  	
	}
	
}